import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/doctor_patrol/doctor_patrol_model.dart';
import 'package:ls_work/doctor_patrol/response/doctor_patrol_record_list.dart';
import 'package:ls_work/widgets/date_range/custom_date_range_picker.dart';

class DoctorPatrolRecordViewModel
    extends BaseListViewModel<DoctorPatrolRecordList> {
  DoctorPatrolRecordViewModel(super.context);

  var model = DoctorPatrolModel();
  var format = [yyyy, '-', mm, '-', dd];

  @override
  Future<List<DoctorPatrolRecordList>> requestListData() async {
    return await model.patrolRecord(
        finishDateFin1: startDateStr,
        finishDateFin2: endDateStr,
        page: page,
        rows: pageLength);
  }

  @override
  void onCreated() {
    super.onCreated();
    initDefaultDate();
    requestRefresh();
  }

  void initDefaultDate() {
    startDateTime = DateTime.now();
    endDateTime = DateTime.now();
    startDateStr = startDateTime?.toDateStr(format) ?? "";
    endDateStr = endDateTime?.toDateStr(format) ?? "";
  }

  void chooseRangeTime() {
    showCustomDateRangePicker(
      context,
      dismissible: true,
      minimumDate: DateTime.now().subtract(const Duration(days: 30)),
      maximumDate: DateTime.now().add(const Duration(days: 100)),
      endDate: endDateTime,
      startDate: startDateTime,
      backgroundColor: Colors.white,
      primaryColor: Colors.blue,
      onApplyClick: (start, end) {
        // appointmentDateStart = start.toDateStr(format);
        // appointmentDateEnd = end.toDateStr(format);
        startDateTime = start;
        endDateTime = end;
        startDateStr = startDateTime?.toDateStr(format) ?? "";
        endDateStr = endDateTime?.toDateStr(format) ?? "";
        notifyListeners();
        requestRefresh();
      },
      onCancelClick: () {},
    );
  }
}
